<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>

<body>
    <div>这是div1</div>
    <div>这是div2</div>
    <p>这是段落 1</p>
    <p>这是段落 2</p>

    <script>

        // 1.获取元素对象
        // var divs = document.querySelectorAll('div');
        // var ps = document.getElementsByTagName('p');

        // for(var i = 0; i < divs.length; i++) {
        //     divs[i].style.border = '1px solid #f00';
        // }

        // for(var i = 0; i < ps.length; i++) {
        //     ps[i].style.border = '1px solid #f00';
        // }


        // 2.将获取回来的所有元素添加到数值中
        var t = document.querySelectorAll;
        // 2.1 定义空数组
        var arr = [];
        // .apply(对象， [参数1， 参数2])
        
        arr.push.apply(arr, t.apply(document, ['div']));
        arr.push.apply(arr, t.apply(document, ['p']));

        // var dome = t.apply(document, ['div'])
        console.log(arr);

        for (var i = 0; i < arr.length; i++) {
            arr[i].style.border = '1px solid #f00';
        }




    </script>

</body>

</html>